import React from 'react'
import { Route } from 'react-router-dom'
import { hasToken } from '@/utils/storage'
import { Redirect } from 'react-router-dom'

export default function PrivateRoute (props) {
  console.log(props, 1111)
  const { path, component } = props
  const token = hasToken()
  const Com = component
  return (
    <Route
      path={path}
      render={() => {
        if (token) return <Com/>
          return <Redirect to={{pathname:'/login',state:{from:props.location.pathname}}}></Redirect>
      }}
    ></Route>
  )
}
